//
//  MenuShezhi.m
//  3GuoTD
//
//  Created by superking on 10-8-24.
//  Copyright 2010 Joymaster. All rights reserved.
//

#import "MenuShezhi.h"
#import	"FileTools.h"




@implementation MenuShezhi

//文字加载（顶部文字和底部按钮）
-(void)WenZi{		
	
	[self panduan];
	switch (language) {
		case 2:
			wzUp=[CCSprite spriteWithFile:@"Gameset_Word_Cn1.png" rect:CGRectMake(0, 0, 112.0, 14.0)];
			wzDown=[CCSprite spriteWithFile:@"Gameset_Word_Cn1.png" rect:CGRectMake(0.0, 42.0, 64.0, 14.0)];
			back=[CCSprite spriteWithFile:@"Gameset_fanhuiCn1.png" rect:CGRectMake(0.0, 0.0, 35.0, 16.0)];
			break;
		case 3:
			wzUp=[CCSprite spriteWithFile:@"Gameset_Word_Cn2.png" rect:CGRectMake(0.0, 0.0, 112.0, 14.0)];
			wzDown=[CCSprite spriteWithFile:@"Gameset_Word_Cn2.png" rect:CGRectMake(0.0, 42.0, 64.0, 14.0)];
			back=[CCSprite spriteWithFile:@"Gameset_fanhuiCn2.png" rect:CGRectMake(0.0, 0.0, 35.0, 16.0)];
			break;
		default:
			wzUp=[CCSprite spriteWithFile:@"Gameset_Word_En.png" rect:CGRectMake(0.0, 0.0, 112.0, 14.0)];
			wzDown=[CCSprite spriteWithFile:@"Gameset_Word_En.png" rect:CGRectMake(0.0, 42.0, 64.0, 14.0)];
			back=[CCSprite spriteWithFile:@"Gameset_fanhuiEn.png" rect:CGRectMake(0.0, 0.0, 34.0, 16.0)];
			break;
	}
	
	wzUp.position=ccp(240,255);
	wzDown.position=ccp(236,24);
	back.anchorPoint=ccp(0,1);
	back.position=ccp(10,315);
	[self addChild:wzUp z:4];
	[self addChild:wzDown z:4];
	[self addChild:back z:4];
	
	//[self BackChange];
}





	-(void) registerWithTouchDispatcher
	{
		[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
	}
	
	-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent*)event
	{		
		CGPoint location = [touch locationInView: [touch view]];
		CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
		
		//back
		CGRect BackRect = CGRectMake(back.position.x, back.position.y-back.contentSize.height, bgLeft.contentSize.width, bgLeft.contentSize.height);
		if (CGRectContainsPoint(BackRect, convertedLocation)) {
			
			[back setTextureRect:CGRectMake(34, 0, 34, 16)];
		}
		
		//音乐
		CGRect MusicRect = CGRectMake(bgLeft.position.x, bgLeft.position.y, bgLeft.contentSize.width, bgLeft.contentSize.height);
		if (CGRectContainsPoint(MusicRect, convertedLocation)) {
			
			[bgLeft setTextureRect:CGRectMake(0, 22, 104, 22)];
		}
		
		//音效
		CGRect SoundRect = CGRectMake(bgRight.position.x-bgRight.contentSize.width, bgRight.position.y, bgRight.contentSize.width, bgRight.contentSize.height);
		if (CGRectContainsPoint(SoundRect, convertedLocation)) {
			[bgRight setTextureRect:CGRectMake(0, 22, 104, 22)];
		}	
		
		//语系选择
		CGRect ContinueRect = CGRectMake(bgDown.position.x-bgDown.contentSize.width/2, bgDown.position.y-bgDown.contentSize.height/2, bgDown.contentSize.width, bgDown.contentSize.height);
		if (CGRectContainsPoint(ContinueRect, convertedLocation)) {
			[bgDown setTextureRect:CGRectMake(0, 28, 216, 28)];
		}	
	
		return YES;
	}
	
		
	- (void)ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
	{
		CGPoint location = [touch locationInView: [touch view]];
		CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
		
		//back
		CGRect BackRect = CGRectMake(back.position.x, back.position.y-back.contentSize.height, bgLeft.contentSize.width, bgLeft.contentSize.height);
		if (CGRectContainsPoint(BackRect, convertedLocation)) {
			
			[back setTextureRect:CGRectMake(0, 0, 34, 16)];
		}
		
		//音乐
		CGRect MusicRect = CGRectMake(bgLeft.position.x, bgLeft.position.y, bgLeft.contentSize.width, bgLeft.contentSize.height);
		if (CGRectContainsPoint(MusicRect, convertedLocation)) {
			
			[bgLeft setTextureRect:CGRectMake(0, 0, 104, 22)];
			[self LeftPressed];
			
			
		}
		
		//音效
		CGRect SoundRect = CGRectMake(bgRight.position.x-bgRight.contentSize.width, bgRight.position.y, bgRight.contentSize.width, bgRight.contentSize.height);
		if (CGRectContainsPoint(SoundRect, convertedLocation)) {
			[bgRight setTextureRect:CGRectMake(0, 0, 104, 22)];
			[self RightPressed];
			
		}	
		
		//语系选择
		CGRect ContinueRect = CGRectMake(bgDown.position.x-bgDown.contentSize.width/2, bgDown.position.y-bgDown.contentSize.height/2, bgDown.contentSize.width, bgDown.contentSize.height);
		if (CGRectContainsPoint(ContinueRect, convertedLocation)) {
			[bgDown setTextureRect:CGRectMake(0, 0, 216, 28)];
		}	
		
	}	




	



@end
